home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-10-21 | 52.8 KB | 1,314 lines |
- Newsgroups: comp.sources.misc
- From: glad@daimi.aau.dk (Michael Glad)
- Subject: v23i097: ufc-crypt - fast crypt/fcrypt routines, Part01/02
- Message-ID: <csm-v23i097=ufc-crypt.205940@sparky.IMD.Sterling.COM>
- X-Md4-Signature: 3387aea353059bd744501a4755629015
- Date: Tue, 22 Oct 1991 02:00:28 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: glad@daimi.aau.dk (Michael Glad)
- Posting-number: Volume 23, Issue 97
- Archive-name: ufc-crypt/part01
- Environment: UNIX, 32BIT
-
- As fast crypt implementations are now becoming easily available, I've decided
- to publish my own highly optimized crypt(3) & fcrypt compatible routines:
- UFC-crypt (UFC == ultra fast crypt). This posting is almost identical to
- the ufc crypt routines posted to alt.sources a few weeks ago.
-
- When doing many operations with the same salt (as is typically the case in
- password cracking programs as Alec Muffet's CRACK program), UFC-crypt is
- 25 - 45 times faster than crypt(3) depending on the machine.
- In the README file, unstructions are given how to plug UFC-crypt into CRACK.
-
- UFC-crypt has been tested on SUN3/4/386, HP 9000 series 300/400/700/800,
- IBM RS/6000 and DEC MIPS systems.
-
- UFC-crypt is covered by the GNU library license version 2.
-
- --- Michael
- ----
- #! /bin/sh
- # This is a shell archive. Remove anything before this line, then feed it
- # into a shell via "sh file" or similar. To overwrite existing files,
- # type "sh file -c".
- # The tool that generated this appeared in the comp.sources.unix newsgroup;
- # send mail to comp-sources-unix@uunet.uu.net if you want that tool.
- # Contents: README COPYING S2o crypt_util.c
- # Wrapped by kent@sparky on Wed Oct 16 15:47:00 1991
- PATH=/bin:/usr/bin:/usr/ucb ; export PATH
- echo If this archive is complete, you will see the following message:
- echo ' "shar: End of archive 1 (of 2)."'
- if test -f 'README' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'README'\"
- else
- echo shar: Extracting \"'README'\" \(4471 characters\)
- sed "s/^X//" >'README' <<'END_OF_FILE'
- X
- X
- X UFC-crypt: ultra fast 'crypt' implementation
- X ============================================
- X
- X @(#)README 2.3 10/04/91
- X
- XDesign goals/non goals:
- X-----------------------
- X
- X- Crypt implementation plugin compatible with crypt(3)/fcrypt
- X
- X- Extremely high performance when used for password cracking.
- X
- X- Portable to most 32 bit machines
- X
- X- Startup time/mixed salt performance not critical
- X
- XFeatures of the implementation:
- X------------------------------
- X
- X- Runs 25-45 times faster than crypt(3) when invoked repeated
- X times with the same salt and varying passwords.
- X With alternating salts, performance is only about 4 times
- X that of crypt(3).
- X
- X- Tested on 68000,386,SPARC,MIPS,HP-PA and RS/6000 systems
- X
- X- Requires 280 kb for tables.
- X
- XAuthor & licensing etc
- X----------------------
- X
- XUFC-crypt is written by Michael Glad, email: glad@daimi.aau.dk.
- XIt is covered by the GNU library license version 2, see the file 'COPYING'.
- X
- XInstalling
- X----------
- X
- XEdit the Makefile setting the variables
- X
- XCRYPT: The encryption module to use; crypt.o should always work.
- X If running on one of the machines for which special support
- X is available, select the appropriate module.
- X
- XFL: If your OS does not have the routines bcopy/bzero in libc,
- X try '-DSYSV'.
- X
- XCC: The compiler to use
- X
- XOFLAG: The highest level of optimization available
- X
- XNow run 'make'. The files 'ufc' and 'libufa.c' are produced.
- XTry 'ufc <number>' to test proper operation and to do benchmarks.
- XIf you link 'ufc' without 'libufc.a' you can benchmark your crypt(3).
- X
- X'libufc.a' can be linked into your applications. It is compatible with
- Xboth crypt(3) and the fcrypt shipped with Alec Muffett's Crack program.
- X
- XFor use in Crack: in 'Sources/Makefile', substitute crack-fcrypt.o with
- Xa path to libufc.a in the CRACKMOD declaration. For benchmarking, use
- Xthe 'speedcrypt' program in the same directory.
- X
- XBenchmark table:
- X---------------
- X
- XIf special assembly language support was used, the machine name is marked
- Xwith '*'. Times are in milliseconds, a line gives how many encryptions UFC-crypt
- Xcan perform per second on the various architectures.
- X
- X|----------|---------------------------------------------|
- X|Machine | SUN* SUN* HP* DIGITAL HP |
- X| | 3/50 ELC 9000/425e DecStation 9000/720 |
- X|----------|---------------------------------------------|
- X| Crypt(3) | 230 37 60 38 17 |
- X| Ufc | 5.2 1.5 1.4 1.2 0,36 |
- X| Ufc/sec | 190 670 715 830 2700 |
- X|----------|---------------------------------------------|
- X| Speedup | 45 25 43 32 47 |
- X|----------|---------------------------------------------|
- X
- XIt seems as if performance is limited by CPU bus and data cache capacity.
- XE.g. on a SUN4, UFC-crypt reads almost 10 mb/sec into the CPU
- Xregisters. As 128kb of memory are swept during an encryption, it may also
- Xmisbehave with datacaches.
- X
- XOptimizations:
- X-------------
- X
- XHere are the optimizations used relative to an ordinary implementation
- Xsuch as the one said to be used in crypt(3).
- X
- XMajor optimizations
- X*******************
- X
- X- Keep data packed as bits in integer variables -- allows for
- X fast permutations & parallel xor's in CPU hardware.
- X
- X- Let adjacent final & initial permutations collapse.
- X
- X- Keep working data in 'E expanded' format all the time.
- X
- X- Implement DES 'f' function mostly by table lookup
- X
- X- Calculate the above function on 12 bit basis rather than 6
- X as would be the most natural. This eats core for tables
- X but it's critical for performance.
- X
- X- Implement setup routines so that performance is limited by the DES
- X inner loops only. At the moment the key calculation routine accounts for
- X a rather unavoidable 16% of the CPU usage.
- X
- XMinor (dirty) optimizations
- X***************************
- X
- X- combine iterations of DES inner loop so that DES only loops
- X 8 times. This saves a lot of variable swapping.
- X
- X- Implement key access by a walking pointer rather than coding
- X as array indexing.
- X
- X- As described, the table based f function uses a 3 dimensional array:
- X
- X sb ['number of 12 bit segment']['12 bit index']['48 bit half index']
- X
- X Code the routine with 4 (one dimensional) vectors.
- X
- X- Design the internal data format & uglify the DES loops so that
- X the compiler does not need to do bit shifts when indexing vectors.
- X
- X- For selected architectures, code the quite little crypt function itself
- X in assembly language but keep the support routines in C.
- X
- END_OF_FILE
- if test 4471 -ne `wc -c <'README'`; then
- echo shar: \"'README'\" unpacked with wrong size!
- fi
- # end of 'README'
- fi
- if test -f 'COPYING' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'COPYING'\"
- else
- echo shar: Extracting \"'COPYING'\" \(25265 characters\)
- sed "s/^X//" >'COPYING' <<'END_OF_FILE'
- X GNU LIBRARY GENERAL PUBLIC LICENSE
- X Version 2, June 1991
- X
- X Copyright (C) 1991 Free Software Foundation, Inc.
- X 675 Mass Ave, Cambridge, MA 02139, USA
- X Everyone is permitted to copy and distribute verbatim copies
- X of this license document, but changing it is not allowed.
- X
- X[This is the first released version of the library GPL. It is
- X numbered 2 because it goes with version 2 of the ordinary GPL.]
- X
- X Preamble
- X
- X The licenses for most software are designed to take away your
- Xfreedom to share and change it. By contrast, the GNU General Public
- XLicenses are intended to guarantee your freedom to share and change
- Xfree software--to make sure the software is free for all its users.
- X
- X This license, the Library General Public License, applies to some
- Xspecially designated Free Software Foundation software, and to any
- Xother libraries whose authors decide to use it. You can use it for
- Xyour libraries, too.
- X
- X When we speak of free software, we are referring to freedom, not
- Xprice. Our General Public Licenses are designed to make sure that you
- Xhave the freedom to distribute copies of free software (and charge for
- Xthis service if you wish), that you receive source code or can get it
- Xif you want it, that you can change the software or use pieces of it
- Xin new free programs; and that you know you can do these things.
- X
- X To protect your rights, we need to make restrictions that forbid
- Xanyone to deny you these rights or to ask you to surrender the rights.
- XThese restrictions translate to certain responsibilities for you if
- Xyou distribute copies of the library, or if you modify it.
- X
- X For example, if you distribute copies of the library, whether gratis
- Xor for a fee, you must give the recipients all the rights that we gave
- Xyou. You must make sure that they, too, receive or can get the source
- Xcode. If you link a program with the library, you must provide
- Xcomplete object files to the recipients so that they can relink them
- Xwith the library, after making changes to the library and recompiling
- Xit. And you must show them these terms so they know their rights.
- X
- X Our method of protecting your rights has two steps: (1) copyright
- Xthe library, and (2) offer you this license which gives you legal
- Xpermission to copy, distribute and/or modify the library.
- X
- X Also, for each distributor's protection, we want to make certain
- Xthat everyone understands that there is no warranty for this free
- Xlibrary. If the library is modified by someone else and passed on, we
- Xwant its recipients to know that what they have is not the original
- Xversion, so that any problems introduced by others will not reflect on
- Xthe original authors' reputations.
- X
- X Finally, any free program is threatened constantly by software
- Xpatents. We wish to avoid the danger that companies distributing free
- Xsoftware will individually obtain patent licenses, thus in effect
- Xtransforming the program into proprietary software. To prevent this,
- Xwe have made it clear that any patent must be licensed for everyone's
- Xfree use or not licensed at all.
- X
- X Most GNU software, including some libraries, is covered by the ordinary
- XGNU General Public License, which was designed for utility programs. This
- Xlicense, the GNU Library General Public License, applies to certain
- Xdesignated libraries. This license is quite different from the ordinary
- Xone; be sure to read it in full, and don't assume that anything in it is
- Xthe same as in the ordinary license.
- X
- X The reason we have a separate public license for some libraries is that
- Xthey blur the distinction we usually make between modifying or adding to a
- Xprogram and simply using it. Linking a program with a library, without
- Xchanging the library, is in some sense simply using the library, and is
- Xanalogous to running a utility program or application program. However, in
- Xa textual and legal sense, the linked executable is a combined work, a
- Xderivative of the original library, and the ordinary General Public License
- Xtreats it as such.
- X
- X Because of this blurred distinction, using the ordinary General
- XPublic License for libraries did not effectively promote software
- Xsharing, because most developers did not use the libraries. We
- Xconcluded that weaker conditions might promote sharing better.
- X
- X However, unrestricted linking of non-free programs would deprive the
- Xusers of those programs of all benefit from the free status of the
- Xlibraries themselves. This Library General Public License is intended to
- Xpermit developers of non-free programs to use free libraries, while
- Xpreserving your freedom as a user of such programs to change the free
- Xlibraries that are incorporated in them. (We have not seen how to achieve
- Xthis as regards changes in header files, but we have achieved it as regards
- Xchanges in the actual functions of the Library.) The hope is that this
- Xwill lead to faster development of free libraries.
- X
- X The precise terms and conditions for copying, distribution and
- Xmodification follow. Pay close attention to the difference between a
- X"work based on the library" and a "work that uses the library". The
- Xformer contains code derived from the library, while the latter only
- Xworks together with the library.
- X
- X Note that it is possible for a library to be covered by the ordinary
- XGeneral Public License rather than by this special one.
- X
- X GNU LIBRARY GENERAL PUBLIC LICENSE
- X TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- X
- X 0. This License Agreement applies to any software library which
- Xcontains a notice placed by the copyright holder or other authorized
- Xparty saying it may be distributed under the terms of this Library
- XGeneral Public License (also called "this License"). Each licensee is
- Xaddressed as "you".
- X
- X A "library" means a collection of software functions and/or data
- Xprepared so as to be conveniently linked with application programs
- X(which use some of those functions and data) to form executables.
- X
- X The "Library", below, refers to any such software library or work
- Xwhich has been distributed under these terms. A "work based on the
- XLibrary" means either the Library or any derivative work under
- Xcopyright law: that is to say, a work containing the Library or a
- Xportion of it, either verbatim or with modifications and/or translated
- Xstraightforwardly into another language. (Hereinafter, translation is
- Xincluded without limitation in the term "modification".)
- X
- X "Source code" for a work means the preferred form of the work for
- Xmaking modifications to it. For a library, complete source code means
- Xall the source code for all modules it contains, plus any associated
- Xinterface definition files, plus the scripts used to control compilation
- Xand installation of the library.
- X
- X Activities other than copying, distribution and modification are not
- Xcovered by this License; they are outside its scope. The act of
- Xrunning a program using the Library is not restricted, and output from
- Xsuch a program is covered only if its contents constitute a work based
- Xon the Library (independent of the use of the Library in a tool for
- Xwriting it). Whether that is true depends on what the Library does
- Xand what the program that uses the Library does.
- X
- X 1. You may copy and distribute verbatim copies of the Library's
- Xcomplete source code as you receive it, in any medium, provided that
- Xyou conspicuously and appropriately publish on each copy an
- Xappropriate copyright notice and disclaimer of warranty; keep intact
- Xall the notices that refer to this License and to the absence of any
- Xwarranty; and distribute a copy of this License along with the
- XLibrary.
- X
- X You may charge a fee for the physical act of transferring a copy,
- Xand you may at your option offer warranty protection in exchange for a
- Xfee.
- X
- X 2. You may modify your copy or copies of the Library or any portion
- Xof it, thus forming a work based on the Library, and copy and
- Xdistribute such modifications or work under the terms of Section 1
- Xabove, provided that you also meet all of these conditions:
- X
- X a) The modified work must itself be a software library.
- X
- X b) You must cause the files modified to carry prominent notices
- X stating that you changed the files and the date of any change.
- X
- X c) You must cause the whole of the work to be licensed at no
- X charge to all third parties under the terms of this License.
- X
- X d) If a facility in the modified Library refers to a function or a
- X table of data to be supplied by an application program that uses
- X the facility, other than as an argument passed when the facility
- X is invoked, then you must make a good faith effort to ensure that,
- X in the event an application does not supply such function or
- X table, the facility still operates, and performs whatever part of
- X its purpose remains meaningful.
- X
- X (For example, a function in a library to compute square roots has
- X a purpose that is entirely well-defined independent of the
- X application. Therefore, Subsection 2d requires that any
- X application-supplied function or table used by this function must
- X be optional: if the application does not supply it, the square
- X root function must still compute square roots.)
- X
- XThese requirements apply to the modified work as a whole. If
- Xidentifiable sections of that work are not derived from the Library,
- Xand can be reasonably considered independent and separate works in
- Xthemselves, then this License, and its terms, do not apply to those
- Xsections when you distribute them as separate works. But when you
- Xdistribute the same sections as part of a whole which is a work based
- Xon the Library, the distribution of the whole must be on the terms of
- Xthis License, whose permissions for other licensees extend to the
- Xentire whole, and thus to each and every part regardless of who wrote
- Xit.
- X
- XThus, it is not the intent of this section to claim rights or contest
- Xyour rights to work written entirely by you; rather, the intent is to
- Xexercise the right to control the distribution of derivative or
- Xcollective works based on the Library.
- X
- XIn addition, mere aggregation of another work not based on the Library
- Xwith the Library (or with a work based on the Library) on a volume of
- Xa storage or distribution medium does not bring the other work under
- Xthe scope of this License.
- X
- X 3. You may opt to apply the terms of the ordinary GNU General Public
- XLicense instead of this License to a given copy of the Library. To do
- Xthis, you must alter all the notices that refer to this License, so
- Xthat they refer to the ordinary GNU General Public License, version 2,
- Xinstead of to this License. (If a newer version than version 2 of the
- Xordinary GNU General Public License has appeared, then you can specify
- Xthat version instead if you wish.) Do not make any other change in
- Xthese notices.
- X
- X Once this change is made in a given copy, it is irreversible for
- Xthat copy, so the ordinary GNU General Public License applies to all
- Xsubsequent copies and derivative works made from that copy.
- X
- X This option is useful when you wish to copy part of the code of
- Xthe Library into a program that is not a library.
- X
- X 4. You may copy and distribute the Library (or a portion or
- Xderivative of it, under Section 2) in object code or executable form
- Xunder the terms of Sections 1 and 2 above provided that you accompany
- Xit with the complete corresponding machine-readable source code, which
- Xmust be distributed under the terms of Sections 1 and 2 above on a
- Xmedium customarily used for software interchange.
- X
- X If distribution of object code is made by offering access to copy
- Xfrom a designated place, then offering equivalent access to copy the
- Xsource code from the same place satisfies the requirement to
- Xdistribute the source code, even though third parties are not
- Xcompelled to copy the source along with the object code.
- X
- X 5. A program that contains no derivative of any portion of the
- XLibrary, but is designed to work with the Library by being compiled or
- Xlinked with it, is called a "work that uses the Library". Such a
- Xwork, in isolation, is not a derivative work of the Library, and
- Xtherefore falls outside the scope of this License.
- X
- X However, linking a "work that uses the Library" with the Library
- Xcreates an executable that is a derivative of the Library (because it
- Xcontains portions of the Library), rather than a "work that uses the
- Xlibrary". The executable is therefore covered by this License.
- XSection 6 states terms for distribution of such executables.
- X
- X When a "work that uses the Library" uses material from a header file
- Xthat is part of the Library, the object code for the work may be a
- Xderivative work of the Library even though the source code is not.
- XWhether this is true is especially significant if the work can be
- Xlinked without the Library, or if the work is itself a library. The
- Xthreshold for this to be true is not precisely defined by law.
- X
- X If such an object file uses only numerical parameters, data
- Xstructure layouts and accessors, and small macros and small inline
- Xfunctions (ten lines or less in length), then the use of the object
- Xfile is unrestricted, regardless of whether it is legally a derivative
- Xwork. (Executables containing this object code plus portions of the
- XLibrary will still fall under Section 6.)
- X
- X Otherwise, if the work is a derivative of the Library, you may
- Xdistribute the object code for the work under the terms of Section 6.
- XAny executables containing that work also fall under Section 6,
- Xwhether or not they are linked directly with the Library itself.
- X
- X 6. As an exception to the Sections above, you may also compile or
- Xlink a "work that uses the Library" with the Library to produce a
- Xwork containing portions of the Library, and distribute that work
- Xunder terms of your choice, provided that the terms permit
- Xmodification of the work for the customer's own use and reverse
- Xengineering for debugging such modifications.
- X
- X You must give prominent notice with each copy of the work that the
- XLibrary is used in it and that the Library and its use are covered by
- Xthis License. You must supply a copy of this License. If the work
- Xduring execution displays copyright notices, you must include the
- Xcopyright notice for the Library among them, as well as a reference
- Xdirecting the user to the copy of this License. Also, you must do one
- Xof these things:
- X
- X a) Accompany the work with the complete corresponding
- X machine-readable source code for the Library including whatever
- X changes were used in the work (which must be distributed under
- X Sections 1 and 2 above); and, if the work is an executable linked
- X with the Library, with the complete machine-readable "work that
- X uses the Library", as object code and/or source code, so that the
- X user can modify the Library and then relink to produce a modified
- X executable containing the modified Library. (It is understood
- X that the user who changes the contents of definitions files in the
- X Library will not necessarily be able to recompile the application
- X to use the modified definitions.)
- X
- X b) Accompany the work with a written offer, valid for at
- X least three years, to give the same user the materials
- X specified in Subsection 6a, above, for a charge no more
- X than the cost of performing this distribution.
- X
- X c) If distribution of the work is made by offering access to copy
- X from a designated place, offer equivalent access to copy the above
- X specified materials from the same place.
- X
- X d) Verify that the user has already received a copy of these
- X materials or that you have already sent this user a copy.
- X
- X For an executable, the required form of the "work that uses the
- XLibrary" must include any data and utility programs needed for
- Xreproducing the executable from it. However, as a special exception,
- Xthe source code distributed need not include anything that is normally
- Xdistributed (in either source or binary form) with the major
- Xcomponents (compiler, kernel, and so on) of the operating system on
- Xwhich the executable runs, unless that component itself accompanies
- Xthe executable.
- X
- X It may happen that this requirement contradicts the license
- Xrestrictions of other proprietary libraries that do not normally
- Xaccompany the operating system. Such a contradiction means you cannot
- Xuse both them and the Library together in an executable that you
- Xdistribute.
- X
- X 7. You may place library facilities that are a work based on the
- XLibrary side-by-side in a single library together with other library
- Xfacilities not covered by this License, and distribute such a combined
- Xlibrary, provided that the separate distribution of the work based on
- Xthe Library and of the other library facilities is otherwise
- Xpermitted, and provided that you do these two things:
- X
- X a) Accompany the combined library with a copy of the same work
- X based on the Library, uncombined with any other library
- X facilities. This must be distributed under the terms of the
- X Sections above.
- X
- X b) Give prominent notice with the combined library of the fact
- X that part of it is a work based on the Library, and explaining
- X where to find the accompanying uncombined form of the same work.
- X
- X 8. You may not copy, modify, sublicense, link with, or distribute
- Xthe Library except as expressly provided under this License. Any
- Xattempt otherwise to copy, modify, sublicense, link with, or
- Xdistribute the Library is void, and will automatically terminate your
- Xrights under this License. However, parties who have received copies,
- Xor rights, from you under this License will not have their licenses
- Xterminated so long as such parties remain in full compliance.
- X
- X 9. You are not required to accept this License, since you have not
- Xsigned it. However, nothing else grants you permission to modify or
- Xdistribute the Library or its derivative works. These actions are
- Xprohibited by law if you do not accept this License. Therefore, by
- Xmodifying or distributing the Library (or any work based on the
- XLibrary), you indicate your acceptance of this License to do so, and
- Xall its terms and conditions for copying, distributing or modifying
- Xthe Library or works based on it.
- X
- X 10. Each time you redistribute the Library (or any work based on the
- XLibrary), the recipient automatically receives a license from the
- Xoriginal licensor to copy, distribute, link with or modify the Library
- Xsubject to these terms and conditions. You may not impose any further
- Xrestrictions on the recipients' exercise of the rights granted herein.
- XYou are not responsible for enforcing compliance by third parties to
- Xthis License.
- X
- X 11. If, as a consequence of a court judgment or allegation of patent
- Xinfringement or for any other reason (not limited to patent issues),
- Xconditions are imposed on you (whether by court order, agreement or
- Xotherwise) that contradict the conditions of this License, they do not
- Xexcuse you from the conditions of this License. If you cannot
- Xdistribute so as to satisfy simultaneously your obligations under this
- XLicense and any other pertinent obligations, then as a consequence you
- Xmay not distribute the Library at all. For example, if a patent
- Xlicense would not permit royalty-free redistribution of the Library by
- Xall those who receive copies directly or indirectly through you, then
- Xthe only way you could satisfy both it and this License would be to
- Xrefrain entirely from distribution of the Library.
- X
- XIf any portion of this section is held invalid or unenforceable under any
- Xparticular circumstance, the balance of the section is intended to apply,
- Xand the section as a whole is intended to apply in other circumstances.
- X
- XIt is not the purpose of this section to induce you to infringe any
- Xpatents or other property right claims or to contest validity of any
- Xsuch claims; this section has the sole purpose of protecting the
- Xintegrity of the free software distribution system which is
- Ximplemented by public license practices. Many people have made
- Xgenerous contributions to the wide range of software distributed
- Xthrough that system in reliance on consistent application of that
- Xsystem; it is up to the author/donor to decide if he or she is willing
- Xto distribute software through any other system and a licensee cannot
- Ximpose that choice.
- X
- XThis section is intended to make thoroughly clear what is believed to
- Xbe a consequence of the rest of this License.
- X
- X 12. If the distribution and/or use of the Library is restricted in
- Xcertain countries either by patents or by copyrighted interfaces, the
- Xoriginal copyright holder who places the Library under this License may add
- Xan explicit geographical distribution limitation excluding those countries,
- Xso that distribution is permitted only in or among countries not thus
- Xexcluded. In such case, this License incorporates the limitation as if
- Xwritten in the body of this License.
- X
- X 13. The Free Software Foundation may publish revised and/or new
- Xversions of the Library General Public License from time to time.
- XSuch new versions will be similar in spirit to the present version,
- Xbut may differ in detail to address new problems or concerns.
- X
- XEach version is given a distinguishing version number. If the Library
- Xspecifies a version number of this License which applies to it and
- X"any later version", you have the option of following the terms and
- Xconditions either of that version or of any later version published by
- Xthe Free Software Foundation. If the Library does not specify a
- Xlicense version number, you may choose any version ever published by
- Xthe Free Software Foundation.
- X
- X 14. If you wish to incorporate parts of the Library into other free
- Xprograms whose distribution conditions are incompatible with these,
- Xwrite to the author to ask for permission. For software which is
- Xcopyrighted by the Free Software Foundation, write to the Free
- XSoftware Foundation; we sometimes make exceptions for this. Our
- Xdecision will be guided by the two goals of preserving the free status
- Xof all derivatives of our free software and of promoting the sharing
- Xand reuse of software generally.
- X
- X NO WARRANTY
- X
- X 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
- XWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
- XEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
- XOTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
- XKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
- XIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- XPURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
- XLIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
- XTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
- X
- X 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
- XWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
- XAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
- XFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
- XCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
- XLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
- XRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
- XFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
- XSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
- XDAMAGES.
- X
- X END OF TERMS AND CONDITIONS
- X
- X Appendix: How to Apply These Terms to Your New Libraries
- X
- X If you develop a new library, and you want it to be of the greatest
- Xpossible use to the public, we recommend making it free software that
- Xeveryone can redistribute and change. You can do so by permitting
- Xredistribution under these terms (or, alternatively, under the terms of the
- Xordinary General Public License).
- X
- X To apply these terms, attach the following notices to the library. It is
- Xsafest to attach them to the start of each source file to most effectively
- Xconvey the exclusion of warranty; and each file should have at least the
- X"copyright" line and a pointer to where the full notice is found.
- X
- X <one line to give the library's name and a brief idea of what it does.>
- X Copyright (C) <year> <name of author>
- X
- X This library is free software; you can redistribute it and/or
- X modify it under the terms of the GNU Library General Public
- X License as published by the Free Software Foundation; either
- X version 2 of the License, or (at your option) any later version.
- X
- X This library is distributed in the hope that it will be useful,
- X but WITHOUT ANY WARRANTY; without even the implied warranty of
- X MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X Library General Public License for more details.
- X
- X You should have received a copy of the GNU Library General Public
- X License along with this library; if not, write to the Free
- X Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X
- XAlso add information on how to contact you by electronic and paper mail.
- X
- XYou should also get your employer (if you work as a programmer) or your
- Xschool, if any, to sign a "copyright disclaimer" for the library, if
- Xnecessary. Here is a sample; alter the names:
- X
- X Yoyodyne, Inc., hereby disclaims all copyright interest in the
- X library `Frob' (a library for tweaking knobs) written by James Random Hacker.
- X
- X <signature of Ty Coon>, 1 April 1990
- X Ty Coon, President of Vice
- X
- XThat's all there is to it!
- END_OF_FILE
- if test 25265 -ne `wc -c <'COPYING'`; then
- echo shar: \"'COPYING'\" unpacked with wrong size!
- fi
- # end of 'COPYING'
- fi
- if test -f 'S2o' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'S2o'\"
- else
- echo shar: Extracting \"'S2o'\" \(969 characters\)
- sed "s/^X//" >'S2o' <<'END_OF_FILE'
- X#!/bin/csh -f
- X
- X# UFC-crypt: ultra fast crypt(3) implementation
- X# Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk
- X#
- X# This library is free software; you can redistribute it and/or
- X# modify it under the terms of the GNU Library General Public
- X# License as published by the Free Software Foundation; either
- X# version 2 of the License, or (at your option) any later version.
- X#
- X# This library is distributed in the hope that it will be useful,
- X# but WITHOUT ANY WARRANTY; without even the implied warranty of
- X# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X# Library General Public License for more details.
- X#
- X# You should have received a copy of the GNU Library General Public
- X# License along with this library; if not, write to the Free
- X# Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X#
- X# @(#)S2o 2.2 10/04/91
- X#
- X# Preprocessor compiling .S files into .o files
- X#
- X
- X/lib/cpp -P $1 | tr \; '\012' > ./tmp.s
- Xas ./tmp.s -o $2
- END_OF_FILE
- if test 969 -ne `wc -c <'S2o'`; then
- echo shar: \"'S2o'\" unpacked with wrong size!
- fi
- chmod +x 'S2o'
- # end of 'S2o'
- fi
- if test -f 'crypt_util.c' -a "${1}" != "-c" ; then
- echo shar: Will not clobber existing file \"'crypt_util.c'\"
- else
- echo shar: Extracting \"'crypt_util.c'\" \(18287 characters\)
- sed "s/^X//" >'crypt_util.c' <<'END_OF_FILE'
- X/*
- X * UFC-crypt: ultra fast crypt(3) implementation
- X *
- X * Copyright (C) 1991, Michael Glad, email: glad@daimi.aau.dk
- X *
- X * This library is free software; you can redistribute it and/or
- X * modify it under the terms of the GNU Library General Public
- X * License as published by the Free Software Foundation; either
- X * version 2 of the License, or (at your option) any later version.
- X *
- X * This library is distributed in the hope that it will be useful,
- X * but WITHOUT ANY WARRANTY; without even the implied warranty of
- X * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- X * Library General Public License for more details.
- X *
- X * You should have received a copy of the GNU Library General Public
- X * License along with this library; if not, write to the Free
- X * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- X *
- X * @(#)crypt_util.c 2.2 10/04/91
- X *
- X * Support routines
- X *
- X */
- X
- X#ifdef DEBUG
- X#include <stdio.h>
- X#endif
- X
- X#include "patchlevel.h"
- X
- X#ifdef SYSV
- X#define bzero(addr, cnt) memset(addr, 0, cnt)
- X#define bcopy(from, to, len) memcpy(to, from, len)
- X#endif
- X
- X/* Permutation done once on the 56 bit
- X key derived from the original 8 byte ASCII key.
- X*/
- Xstatic unsigned long pc1[56] =
- X { 57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
- X 10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
- X 63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
- X 14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
- X };
- X
- X/* How much to rotate each 28 bit half of the pc1 permutated
- X 56 bit key before using pc2 to give the i' key
- X*/
- Xstatic unsigned long totrot[16] =
- X { 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 };
- X
- X/* Permutation giving the key of the i' DES round */
- Xstatic unsigned long pc2[48] =
- X { 14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
- X 23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
- X 41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
- X 44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
- X };
- X
- X/* Reference copy of the expansion table which selects
- X bits from the 32 bit intermediate result.
- X*/
- Xstatic unsigned long eref[48] =
- X { 32, 1, 2, 3, 4, 5, 4, 5, 6, 7, 8, 9,
- X 8, 9, 10, 11, 12, 13, 12, 13, 14, 15, 16, 17,
- X 16, 17, 18, 19, 20, 21, 20, 21, 22, 23, 24, 25,
- X 24, 25, 26, 27, 28, 29, 28, 29, 30, 31, 32, 1
- X };
- Xstatic unsigned long disturbed_e[48];
- Xstatic unsigned long e_inverse[64];
- X
- X/* Permutation done on the result of sbox lookups */
- Xstatic unsigned long perm32[32] =
- X { 16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
- X 2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
- X };
- X
- X/* The sboxes */
- Xstatic unsigned long sbox[8][4][16]=
- X { { { 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7 },
- X { 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8 },
- X { 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0 },
- X { 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13 }
- X },
- X
- X { { 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10 },
- X { 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5 },
- X { 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15 },
- X { 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9 }
- X },
- X
- X { { 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8 },
- X { 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1 },
- X { 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7 },
- X { 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12 }
- X },
- X
- X { { 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15 },
- X { 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9 },
- X { 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4 },
- X { 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14 }
- X },
- X
- X { { 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9 },
- X { 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6 },
- X { 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14 },
- X { 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3 }
- X },
- X
- X { { 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11 },
- X { 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8 },
- X { 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6 },
- X { 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13 }
- X },
- X
- X { { 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1 },
- X { 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6 },
- X { 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2 },
- X { 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12 }
- X },
- X
- X { { 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7 },
- X { 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2 },
- X { 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8 },
- X { 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11 }
- X }
- X };
- X
- X#ifdef notdef
- X
- X/* This is the initial permutation matrix -- we have no
- X use for it, but it is needed if you will develop
- X this module into a general DES package.
- X*/
- Xstatic unsigned char inital_perm[64] =
- X { 58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
- X 62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
- X 57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
- X 61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
- X };
- X
- X#endif
- X
- X/* Final permutation matrix -- not used directly */
- Xstatic unsigned char final_perm[64] =
- X { 40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31,
- X 38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29,
- X 36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27,
- X 34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25
- X };
- X
- X/* The 16 DES keys in BITMASK format */
- Xunsigned long keytab[16][2];
- X
- X#define ascii_to_bin(c) ((c)>='a'?(c-59):(c)>='A'?((c)-53):(c)-'.')
- X#define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
- X
- X/* Macro to set a bit (0..23) */
- X#define BITMASK(i) ( (1<<(11-(i)%12+3)) << ((i)<12?16:0) )
- X
- X/* sb arrays:
- X
- X Workhorses of the inner loop of the DES implementation.
- X They do sbox lookup, shifting of this value, 32 bit
- X permutation and E permutation for the next round.
- X
- X Kept in 'BITMASK' format.
- X
- X*/
- X
- Xunsigned long sb0[8192],sb1[8192],sb2[8192],sb3[8192];
- Xstatic unsigned long *sb[4] = {sb0,sb1,sb2,sb3};
- X
- X/* eperm32tab: do 32 bit permutation and E selection
- X
- X The first index is the byte number in the 32 bit value to be permuted
- X - second - is the value of this byte
- X - third - selects the two 32 bit values
- X
- X The table is used and generated internally in init_des to speed it up
- X
- X*/
- Xstatic unsigned long eperm32tab[4][256][2];
- X
- X/* mk_keytab_table: fast way of generating keytab from ASCII key
- X
- X The first index is the byte number in the 8 byte ASCII key
- X - second - - - current DES round i.e. the key number
- X - third - distinguishes between the two 24 bit halfs of
- X the selected key
- X - fourth - selects the 7 bits actually used of each byte
- X
- X The table is kept in the format generated by the BITMASK macro
- X
- X*/
- Xstatic unsigned long mk_keytab_table[8][16][2][128];
- X
- X
- X/* efp: undo an extra e selection and do final
- X permutation giving the DES result.
- X
- X Invoked 6 bit a time on two 48 bit values
- X giving two 32 bit longs.
- X*/
- Xstatic unsigned long efp[16][64][2];
- X
- X
- Xstatic unsigned char bytemask[8] =
- X { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
- X
- X
- Xstatic unsigned long longmask[32] =
- X { 0x80000000, 0x40000000, 0x20000000, 0x10000000,
- X 0x08000000, 0x04000000, 0x02000000, 0x01000000,
- X 0x00800000, 0x00400000, 0x00200000, 0x00100000,
- X 0x00080000, 0x00040000, 0x00020000, 0x00010000,
- X 0x00008000, 0x00004000, 0x00002000, 0x00001000,
- X 0x00000800, 0x00000400, 0x00000200, 0x00000100,
- X 0x00000080, 0x00000040, 0x00000020, 0x00000010,
- X 0x00000008, 0x00000004, 0x00000002, 0x00000001
- X };
- X
- X#ifdef DEBUG
- X
- X/* For debugging */
- X
- Xpr_bits(a,n)
- X unsigned long *a;
- X unsigned long n;
- X { unsigned long i,j,t,tmp;
- X n/=8;
- X for(i=0; i<n; i++)
- X { tmp=0;
- X for(j=0; j<8; j++)
- X { t=8*i+j;
- X tmp|=(a[t/24] & BITMASK(t % 24))?bytemask[j]:0;
- X }
- X (void)printf("%02x ",tmp);
- X }
- X printf(" ");
- X }
- X
- Xstatic set_bits(v,b)
- X unsigned long v;
- X unsigned long *b;
- X { unsigned long i;
- X *b = 0;
- X for(i=0; i<24; i++)
- X if(v & longmask[8+i])
- X *b |= BITMASK(i);
- X }
- X
- X#endif
- X
- Xstatic unsigned long initialized = 0;
- X
- X/* lookup a 6 bit value in sbox */
- X
- X#define s_lookup(i,s) sbox[(i)][(((s)>>4) & 0x2)|((s) & 0x1)][((s)>>1) & 0xf];
- X
- X/* Generate the mk_keytab_table once in a program execution */
- X
- Xvoid init_des()
- X { unsigned long tbl_long,bit_within_long,comes_from_bit;
- X unsigned long bit,sg,j;
- X unsigned long bit_within_byte,key_byte,byte_value;
- X unsigned long round,mask;
- X
- X bzero((char*)mk_keytab_table,sizeof mk_keytab_table);
- X
- X for(round=0; round<16; round++)
- X for(bit=0; bit<48; bit++)
- X { tbl_long = bit / 24;
- X bit_within_long = bit % 24;
- X
- X /* from which bit in the key halves does it origin? */
- X comes_from_bit = pc2[bit] - 1;
- X
- X /* undo the rotation done before pc2 */
- X if(comes_from_bit>=28)
- X comes_from_bit = 28 + (comes_from_bit + totrot[round]) % 28;
- X else
- X comes_from_bit = (comes_from_bit + totrot[round]) % 28;
- X
- X /* undo the initial key half forming permutation */
- X comes_from_bit = pc1[comes_from_bit] - 1;
- X
- X /* Now 'comes_from_bit' is the correct number (0..55)
- X of the keybit from which the bit being traced
- X in key 'round' comes from
- X */
- X
- X key_byte = comes_from_bit / 8;
- X bit_within_byte = (comes_from_bit % 8)+1;
- X
- X mask = bytemask[bit_within_byte];
- X
- X for(byte_value=0; byte_value<128; byte_value++)
- X if(byte_value & mask)
- X mk_keytab_table[key_byte][round][tbl_long][byte_value] |=
- X BITMASK(bit_within_long);
- X }
- X
- X /* Now generate the table used to do an combined
- X 32 bit permutation and e expansion
- X
- X We use it because we have to permute 16384 32 bit
- X longs into 48 bit in order to initialize sb.
- X
- X Looping 48 rounds per permutation becomes
- X just too slow...
- X
- X */
- X
- X bzero((char*)eperm32tab,sizeof eperm32tab);
- X for(bit=0; bit<48; bit++)
- X { unsigned long mask1,comes_from;
- X
- X comes_from = perm32[eref[bit]-1]-1;
- X mask1 = bytemask[comes_from % 8];
- X
- X for(j=256; j--;)
- X if(j & mask1)
- X eperm32tab[comes_from/8][j][bit/24] |= BITMASK(bit % 24);
- X }
- X
- X /* Create the sb tables:
- X
- X For each 12 bit segment of an 48 bit intermediate
- X result, the sb table precomputes the two 4 bit
- X values of the sbox lookups done with the two 6
- X bit halves, shifts them to their proper place,
- X sends them through perm32 and finally E expands
- X them so that they are ready for the next
- X DES round.
- X
- X The value looked up is to be xored onto the
- X two 48 bit right halves.
- X */
- X
- X for(sg=0; sg<4; sg++)
- X { unsigned long j1,j2;
- X unsigned long s1,s2;
- X
- X for(j1=0; j1<64; j1++)
- X { s1 = s_lookup(2*sg,j1);
- X for(j2=0; j2<64; j2++)
- X { unsigned long to_permute,inx;
- X
- X s2 = s_lookup(2*sg+1,j2);
- X to_permute = ((s1<<4) | s2) << (24-8*sg);
- X inx = ((j1<<6) | j2) << 1;
- X
- X sb[sg][inx ] = eperm32tab[0][(to_permute >> 24) & 0xff][0];
- X sb[sg][inx+1] = eperm32tab[0][(to_permute >> 24) & 0xff][1];
- X
- X sb[sg][inx ] |= eperm32tab[1][(to_permute >> 16) & 0xff][0];
- X sb[sg][inx+1] |= eperm32tab[1][(to_permute >> 16) & 0xff][1];
- X
- X sb[sg][inx ] |= eperm32tab[2][(to_permute >> 8) & 0xff][0];
- X sb[sg][inx+1] |= eperm32tab[2][(to_permute >> 8) & 0xff][1];
- X
- X sb[sg][inx ] |= eperm32tab[3][(to_permute) & 0xff][0];
- X sb[sg][inx+1] |= eperm32tab[3][(to_permute) & 0xff][1];
- X }
- X }
- X }
- X initialized++;
- X }
- X
- X/* Process the elements of the sb table permuting the
- X bits swapped in the expansion by the current salt.
- X*/
- X
- Xvoid shuffle_sb(k, saltbits)
- X unsigned long *k, saltbits;
- X { int j, x;
- X for(j=4096; j--;) {
- X x = (k[0] ^ k[1]) & saltbits;
- X *k++ ^= x;
- X *k++ ^= x;
- X }
- X }
- X
- X/* Setup the unit for a new salt
- X Hopefully we'll not see a new salt in each crypt call.
- X*/
- X
- Xstatic unsigned char current_salt[3]="&&"; /* invalid value */
- Xstatic unsigned long oldsaltbits = 0;
- X
- Xvoid setup_salt(s)
- X char *s;
- X { unsigned long i,j,saltbits;
- X
- X if(!initialized)
- X init_des();
- X
- X if(s[0]==current_salt[0] && s[1]==current_salt[1])
- X return;
- X current_salt[0]=s[0]; current_salt[1]=s[1];
- X
- X /* This is the only crypt change to DES:
- X entries are swapped in the expansion table
- X according to the bits set in the salt.
- X */
- X
- X saltbits=0;
- X bcopy((char*)eref,(char*)disturbed_e,sizeof eref);
- X for(i=0; i<2; i++)
- X { long c=ascii_to_bin(s[i]);
- X if(c<0 || c>63)
- X c=0;
- X for(j=0; j<6; j++)
- X if((c>>j) & 0x1)
- X { disturbed_e[6*i+j ]=eref[6*i+j+24];
- X disturbed_e[6*i+j+24]=eref[6*i+j ];
- X saltbits |= BITMASK(6*i+j);
- X }
- X }
- X
- X /* Permute the sb table values
- X to reflect the changed e
- X selection table
- X */
- X
- X shuffle_sb(sb0, oldsaltbits ^ saltbits);
- X shuffle_sb(sb1, oldsaltbits ^ saltbits);
- X shuffle_sb(sb2, oldsaltbits ^ saltbits);
- X shuffle_sb(sb3, oldsaltbits ^ saltbits);
- X
- X oldsaltbits = saltbits;
- X
- X /* Create an inverse matrix for disturbed_e telling
- X where to plug out bits if undoing disturbed_e
- X */
- X
- X for(i=48; i--;)
- X { e_inverse[disturbed_e[i]-1 ] = i;
- X e_inverse[disturbed_e[i]-1+32] = i+48;
- X }
- X
- X /* create efp: the matrix used to
- X undo the E expansion and effect final permutation
- X */
- X
- X bzero((char*)efp,sizeof efp);
- X for(i=0; i<64; i++)
- X { unsigned long o_bit,o_long;
- X unsigned long word_value,mask1,mask2,comes_from_f_bit,comes_from_e_bit;
- X unsigned long comes_from_word,bit_within_word;
- X
- X /* See where bit i belongs in the two 32 bit long's */
- X o_long = i / 32; /* 0..1 */
- X o_bit = i % 32; /* 0..31 */
- X
- X /* And find a bit in the e permutated value setting this bit.
- X
- X Note: the e selection may have selected the same bit several
- X times. By the initialization of e_inverse, we only look
- X for one specific instance.
- X */
- X comes_from_f_bit = final_perm[i]-1; /* 0..63 */
- X comes_from_e_bit = e_inverse[comes_from_f_bit]; /* 0..95 */
- X comes_from_word = comes_from_e_bit / 6; /* 0..15 */
- X bit_within_word = comes_from_e_bit % 6; /* 0..5 */
- X
- X mask1 = longmask[bit_within_word+26];
- X mask2 = longmask[o_bit];
- X
- X for(word_value=64; word_value--;)
- X if(word_value & mask1)
- X efp[comes_from_word][word_value][o_long] |= mask2;
- X
- X }
- X
- X }
- X
- X/* Generate the key table before running the 25 DES rounds */
- X
- Xvoid mk_keytab(key)
- X char *key;
- X { unsigned long i,j;
- X unsigned long *k,*mkt;
- X char t;
- X
- X bzero((char*)keytab, sizeof keytab);
- X mkt = &mk_keytab_table[0][0][0][0];
- X
- X for(i=0; (t=(*key++) & 0x7f) && i<8; i++)
- X for(j=0,k = &keytab[0][0]; j<16; j++)
- X { *k++ |= mkt[t]; mkt += 128;
- X *k++ |= mkt[t]; mkt += 128;
- X }
- X for(; i<8; i++)
- X for(j=0,k = &keytab[0][0]; j<16; j++)
- X { *k++ |= mkt[0]; mkt += 128;
- X *k++ |= mkt[0]; mkt += 128;
- X }
- X }
- X
- X/* Do final permutations and convert to ASCII */
- X
- Xchar *output_conversion(l1,l2,r1,r2,salt)
- X unsigned long l1,l2,r1,r2;
- X char *salt;
- X { static char outbuf[14];
- X unsigned long i;
- X unsigned long s,v1,v2;
- X
- X /* Unfortunately we've done an extra E
- X expansion -- undo it at the same time.
- X */
- X
- X v1=v2=0; l1 >>= 3; l2 >>= 3; r1 >>= 3; r2 >>= 3;
- X
- X v1 |= efp[ 3][ l1 & 0x3f][0]; v2 |= efp[ 3][ l1 & 0x3f][1];
- X v1 |= efp[ 2][(l1>>=6) & 0x3f][0]; v2 |= efp[ 2][ l1 & 0x3f][1];
- X v1 |= efp[ 1][(l1>>=10) & 0x3f][0]; v2 |= efp[ 1][ l1 & 0x3f][1];
- X v1 |= efp[ 0][(l1>>=6) & 0x3f][0]; v2 |= efp[ 0][ l1 & 0x3f][1];
- X
- X v1 |= efp[ 7][ l2 & 0x3f][0]; v2 |= efp[ 7][ l2 & 0x3f][1];
- X v1 |= efp[ 6][(l2>>=6) & 0x3f][0]; v2 |= efp[ 6][ l2 & 0x3f][1];
- X v1 |= efp[ 5][(l2>>=10) & 0x3f][0]; v2 |= efp[ 5][ l2 & 0x3f][1];
- X v1 |= efp[ 4][(l2>>=6) & 0x3f][0]; v2 |= efp[ 4][ l2 & 0x3f][1];
- X
- X v1 |= efp[11][ r1 & 0x3f][0]; v2 |= efp[11][ r1 & 0x3f][1];
- X v1 |= efp[10][(r1>>=6) & 0x3f][0]; v2 |= efp[10][ r1 & 0x3f][1];
- X v1 |= efp[ 9][(r1>>=10) & 0x3f][0]; v2 |= efp[ 9][ r1 & 0x3f][1];
- X v1 |= efp[ 8][(r1>>=6) & 0x3f][0]; v2 |= efp[ 8][ r1 & 0x3f][1];
- X
- X v1 |= efp[15][ r2 & 0x3f][0]; v2 |= efp[15][ r2 & 0x3f][1];
- X v1 |= efp[14][(r2>>=6) & 0x3f][0]; v2 |= efp[14][ r2 & 0x3f][1];
- X v1 |= efp[13][(r2>>=10) & 0x3f][0]; v2 |= efp[13][ r2 & 0x3f][1];
- X v1 |= efp[12][(r2>>=6) & 0x3f][0]; v2 |= efp[12][ r2 & 0x3f][1];
- X
- X outbuf[0] = salt[0];
- X outbuf[1] = salt[1] ? salt[1] : salt[0];
- X
- X for(i=0; i<5; i++)
- X outbuf[i+2] = bin_to_ascii((v1>>(26-6*i)) & 0x3f);
- X
- X s = (v2 & 0xf) << 2; /* Save the rightmost 4 bit a moment */
- X v2 = (v2>>2) | ((v1 & 0x3)<<30); /* Shift two bits of v1 onto v2 */
- X
- X for(i=5; i<10; i++)
- X outbuf[i+2] = bin_to_ascii((v2>>(56-6*i)) & 0x3f);
- X
- X outbuf[12] = bin_to_ascii(s);
- X outbuf[13] = 0;
- X
- X return outbuf;
- X }
- X
- Xchar *crypt();
- X
- X/* Stub to provide fcrypt compatibility */
- X
- Xchar *fcrypt(key, salt)
- X char *key;
- X char *salt;
- X { return crypt(key, salt);
- X }
- X
- END_OF_FILE
- if test 18287 -ne `wc -c <'crypt_util.c'`; then
- echo shar: \"'crypt_util.c'\" unpacked with wrong size!
- fi
- # end of 'crypt_util.c'
- fi
- echo shar: End of archive 1 \(of 2\).
- cp /dev/null ark1isdone
- MISSING=""
- for I in 1 2 ; do
- if test ! -f ark${I}isdone ; then
- MISSING="${MISSING} ${I}"
- fi
- done
- if test "${MISSING}" = "" ; then
- echo You have unpacked both archives.
- rm -f ark[1-9]isdone
- else
- echo You still must unpack the following archives:
- echo " " ${MISSING}
- fi
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-